const app = getApp()
const api = require('../../../utils/util')
Page({
    // 页面分享
    onShareAppMessage () {},
    // 分享朋友圈
    onShareTimeline () {},
    data: {
      imagesUrl: app.globalData.imagesUrl,
      showView: true,
      // 全选
      result: [],
      checked: false,
      memberList:[
      
      ]
    },
    // 全选
    checkboxChange(e) {
      this.setData({
        result: e.detail,
      });
      let b = [];
      for(let i = 0; i<this.data.memberList.length; i++){
        b.push(this.data.memberList[i].id)
      }
      let c = e.detail.length === b.length && e.detail.filter(t => !b.includes(t));
      if (c) {
        this.setData({
          checked: true,
        });
      } else {
        this.setData({
          checked: false,
        });
      }
  
    },
    checkAll(e) {
      this.setData({
        checked: e.detail,
      });
      if (e.detail) {
        let b = [];
        for(let i = 0; i<this.data.memberList.length; i++){
          b.push(this.data.memberList[i].id)
        }
        this.setData({
          result: b,
        });
      } else {
        this.setData({
          result: [],
        });
      }
    },
    onLoad: function (options) {
      // 生命周期函数--监听页面加载
      showView: (options.showView == "true" ? true : false)
      let userinfo = app.globalData.userinfo;

      let that = this;

      if(!userinfo){
        wx.navigateTo({
          url: '/pages/login/login',
        })
      }

      let param = {
          ucode : app.globalData.userinfo.ucode,
      }
      
      api.get_member_list(param).then(function(res){
          let memberList  = []
          for(let i =0; i < res.data.length; i++){
            let desc = '';
            if(res.data[i].is_admin == 1){
              desc = '超级管理员';
            }else if(res.data[i].is_manage == 1){
              desc = '内容管理员';
            }else{
              desc = '业务员';
            }

            memberList.push({
              id: res.data[i].id,
              headpic: app.globalData.siteUrl + res.data[i].headpic,
              name: res.data[i].name,
              desc: desc,
            })
          }
          that.setData({
            memberList: memberList 
          })
      })

    }, 
    onChangeShowState: function () {
      var that = this;
      that.setData({
        showView: (!that.data.showView)
      })
    },
    submitHandle: function(){
       wx.redirectTo({
         url: '/pages/enterprise/enterprise-up/enterprise-up',
       })
    },
    del: function(){
      let that = this
      let param = {
        ids:this.data.result
      }
      api.del_enterprise_member(param).then(function(res){
          wx.redirectTo({
            url: '/pages/enterprise/contact/contact',
          })
      })
      
    },
  })